<?php 
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$connect = mysql_connect('localhost','root','');
mysql_select_db("pratice1");
?>
<?php
   if($_SESSION["loggedin"] == true){
   
    if($_SESSION["role"] =="admin")
	{
		header("Location: admin.php");
	}  
	elseif($_SESSION["role"]=="pm")
	{
	    $_SESSION["mgs"]= "permission";
		header('Location: pm.php');
	} 
	elseif($_SESSION["role"]=="tl")
	{
		header('Location: tl.php');
	} 
	elseif($_SESSION["role"]=="trainee")
	{
		header('Location: trainee.php');
	} 
	}





	if(isset($_POST['login']))
	{
	$username = $_POST['username'];
	$password = $_POST['password'];
	$role     = $_POST['role'];
	
			
	$select = "SELECT role from login WHERE username='$username' and password='$password' and role='$role' ";
	$result= mysql_query($select);
	$row=mysql_fetch_array($result);
	//echo $row[username]= $role;
	//print_r($row);
	if(empty($row))
	{
	 echo 'invalid';
	}
	else{
	
	$_SESSION["loggedin"] = true;
    if($row[role]=="admin")
	{
	$_SESSION["role"] = admin;
	header("Location: admin.php");
	}  
	elseif($row[role]=="pm")
	{
	$_SESSION["role"] = pm;
	header('Location: pm.php');
	} 
	elseif($row[role]=="tl")
	{
	$_SESSION["role"] = tl;
	header('Location: tl.php');
	} 
	elseif($row[role]=="trainee")
	{
	$_SESSION["role"] = trainee;
	header('Location: trainee.php');
	} 
	}
	
}
	
?>


<form action="login.php" method="post">
<label>Username</label>
<input type="text" name="username" value="<?php echo $_POST['username'];?>"/>
<label>Password</label>
<input type="password" name="password" value="<?php echo $_POST['password'];?>"/>
<select type="option" name="role">
<option value="admin">admin</option>
<option value="pm">Project manager</option>
<option value="tl">Team Leader</option>
<option value="trainee">Developer</option>
</select>
<input type="submit" name="login" value="login" />
</form>